$(function(){
    rllCount(0);
    rllChart(0);
});
var chartType = 0;
var zyType=null;
var zyStartTime=null;
var zyEndTime=null;
//昨日客流量
function rllCount(type){
    $.get(baseURL + "rll/rllhourcount/rllCountHp", function(r){
        $("#zongy").html(r.zongy);
        $("#southy").html(r.southy);
        $("#northy").html(r.northy);
        $("#zongm").html(r.zongm);
        $("#southm").html(r.southm);
        $("#northm").html(r.northm);
    });
    $.get( "../../rll/rllhourcount/kllChart1/"+type,function(r) {
        $("#zongt").html(Number(r.southList[2])+Number(r.northList[2]));
        $("#southt").html(r.southList[2]);
        $("#northt").html(r.northList[2]);
    });
}
function rllChart(type){
    var startTime=$("#beginTime").val();
    var endTime = $("#endTime").val();
    if(type==2){
         zyStartTime=$("#beginTime").val();
         zyEndTime = $("#endTime").val();
        if(!startTime){
            alert("请选择开始时间！")
            return;
        }else{
            startTime = startTime+" 00:00:00";
        }
        if(!endTime){
            alert("请选择结束时间！")
            return;
        }else{
            endTime = endTime+" 23:59:59";
        }
    }
    if(type ==0){
        zyType = 7;
    }else if(type ==1){
        zyType = 30;
    }
    chartType = type;
    $.ajax({
        type: "POST",
        url: "../../rll/rlldayinfo/rllChartHp",
        data: {
            type:type,
            startTime:startTime,
            endTime:endTime
        },
        success: function(r) {
            var time=r.time;
            var skll=r.skll;
            var nkll=r.nkll;
            var myChart = echarts.init(document.getElementById('rllchart'));
            var option = {
                tooltip : {
                    trigger: 'axis',
                    formatter: function(params) { //自定义函数修改折线图给数据加单位
                        var str = '';//声明一个变量用来存储数据
                        str += '<div>'+ params[0].name +'</div>'; //显示首行的函数
                        for(var i=0; i<params.length; i++) { //图显示的数据较多时需要循环数据，这样才可以成功的给多条数据添加单位
                            str += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>'+ params[i].seriesName +'</span> : <span>'+ params[i].data+'人次' +'</br>';
                        }
                        return str;
                    }
                },
                grid: {
                    x: 46,
                    y:30,
                    x2:32,
                    y2:30,
                    borderWidth: 0
                },
                legend: {
                    data:['南区','北区'],
                    textStyle:{
                        color:"#000"
                    },
                },
                calculable : true,
                xAxis : [
                    {   nameTextStyle:{
                            align: "center",
                        },
                        type : 'category',
                        name:"日期",
                        boundaryGap : false,
                        data : time,
                        splitLine: {
                            show: false
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#a4a7ab'
                            }
                        }
                    }
                ],
                yAxis : [
                    {
                        type : 'value',
                        name:'总数/人次',
                        splitLine: {
                            show: false
                        },
                        axisLabel: {
                            show: true,
                            textStyle: {
                                color: '#a4a7ab'
                            }
                        }

                    }
                ],
                series : [
                    {
                        name:'南区',
                        type:'line',
                        //stack: '人次',
                        data:skll,
                        smooth: true,
                        itemStyle: {
                            normal: {
                                color:"#e15828"
                            }
                        }
                    },
                    {
                        name:'北区',
                        type:'line',
                        // stack: '人次',
                        smooth: true,
                        data:nkll,
                        itemStyle: {
                            normal: {
                                color:"#2e7cff"
                            }
                        }
                    }
                ]
            };
            myChart.setOption(option);
            window.addEventListener("resize",function(){
                myChart.resize();
            });
        }
    });
}
function rllExp(){
    window.location.href =  baseURL + "rll/rlldayinfo/upload?type="+zyType+"&startTime="+zyStartTime+"&endTime="+zyEndTime;
   /* var startTime=$("#beginTime").val();
    var endTime = $("#endTime").val();
    window.location.href =  baseURL + "rll/rlldayinfo/exportrll?type="+chartType+"&&startTime="+startTime+"&&endTime"+endTime;*/
}
